%% 利用小波滤波法对心电图过滤
clc;clear
horse_data = xlsread('E:\马的心电图特征提取\data.xlsx','sheet1');   %读取马的心跳数据
N = 3; %小波变换级别
%% 存储每匹马的数据
horse_1 = horse_data(1,:);       %第1匹马
horse_2 = horse_data(2,:);       %第2匹马
horse_3 = horse_data(3,:);       %第3匹马
horse_4 = horse_data(4,:);       %第4匹马
horse_5 = horse_data(5,:);       %第5匹马
horse_6 = horse_data(6,:);       %第6匹马
horse_7 = horse_data(7,:);       %第7匹马
horse_8 = horse_data(8,:);       %第8匹马
horse_9 = horse_data(9,:);       %第9匹马
%% 滤波处理
figure(1)  %马1~4
x = 1:1:255;
XD1 = wden(horse_1,'sqtwolog','s','sln',N,'db8');   %马1
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD1,'sheet1','A1');
subplot(2,2,1);
plot(x,XD1,'LineWidth',1.5);axis([0 256 0 123]);
title('horse1-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD2 = wden(horse_2,'sqtwolog','s','sln',N,'db8');   %马2
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD2,'sheet1','A2');
subplot(2,2,2);
plot(x,XD2,'LineWidth',1.5);axis([0 256 0 123]);
title('horse2-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD3 = wden(horse_3,'sqtwolog','s','sln',N,'db8');   %马3
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD3,'sheet1','A3');
subplot(2,2,3);
plot(x,XD3,'LineWidth',1.5);axis([0 256 0 123]);
title('horse3-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD4 = wden(horse_4,'sqtwolog','s','sln',N,'db8');   %马4
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD4,'sheet1','A4');
subplot(2,2,4);
plot(x,XD4,'LineWidth',1.5);axis([0 256 0 123]);
title('horse4-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );
%%
figure(2)  %马5~8
XD5 = wden(horse_5,'sqtwolog','s','sln',N,'db8');   %马5
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD5,'sheet1','A5');
subplot(2,2,1);
plot(x,XD5,'LineWidth',1.5);axis([0 256 0 123]);
title('horse5-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD6 = wden(horse_6,'sqtwolog','s','sln',N,'db8');   %马6
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD6,'sheet1','A6');
subplot(2,2,2);
plot(x,XD6,'LineWidth',1.5);axis([0 256 0 123]);
title('horse6-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD7 = wden(horse_7,'sqtwolog','s','sln',N,'db8');   %马7
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD7,'sheet1','A7');
subplot(2,2,3);
plot(x,XD7,'LineWidth',1.5);axis([0 256 0 123]);
title('horse7-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );

XD8 = wden(horse_8,'sqtwolog','s','sln',N,'db8');   %马8
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD8,'sheet1','A8');
subplot(2,2,4);
plot(x,XD8,'LineWidth',1.5);axis([0 256 0 123]);
title('horse8-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );
%%
figure(3)
XD9 = wden(horse_9,'sqtwolog','s','sln',N,'db8');   %马9
xlswrite('E:\马的心电图特征提取\new_data.xlsx',XD9,'sheet1','A9');
plot(x,XD9,'LineWidth',1.5);axis([0 256 0 123]);
title('horse9-filter');xlabel('t/ms');ylabel('mV'); 
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold','FontAngle','italic','linewidth',2 );







